package com.zyx.groovydemo.closure

/**
 * @author Yaxi.Zhang
 * @since 2022/5/7 23:20
 * desc: 闭包入门
 */

def closure = { println 'Hello Groovy!' }

//closure.call()
//closure()

def argumentClosure = { String name, int age ->
    println "Hello ${name}, My age is ${age}"
}
name = 'groovy!'
//argumentClosure.call(name, 20)
//argumentClosure(name, 18)

// it为所有的闭包函数默认拥有的隐式参数
def defaultArguClosure = {
    println "Hello ${it}"
}
// 无返回值闭包的返回值为null
def res = defaultArguClosure(name)
println res

// 有返回值的闭包
def returnClosure = {
   return it
}
